<%@page import="loginmysql.*, java.util.*, logic.*"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%	
	MysqlLogin.connect();

   	String name = request.getParameter( "username" );
	String pass = request.getParameter("password");
	System.out.println(name+" "+pass);
	
	pass = Encryption.hashPassword(pass);
	
	ArrayList<String> aLLogin = MysqlLogin.login(name, pass);
	
	String fullName = aLLogin.get(0);
	int FuncionarioId = Integer.parseInt(aLLogin.get(1));
	int priv = Integer.parseInt(aLLogin.get(2));
	System.out.println(FuncionarioId);
	session.setAttribute("FuncId",FuncionarioId);
	System.out.println("login dio "+fullName);
	if(fullName.equals("e")){
		session.setAttribute( "state","block");
		response.sendRedirect("FormLogin.jsp");
		session.setAttribute( "FullName","");
		System.out.println("badlogin");
		session.setAttribute("error", "Usuario o Contrase&ntilde;a incorrectos");
		fullName="e";
	}else if(priv==1){
		session.setAttribute( "state","none");
   		session.setAttribute( "FullName",fullName );
   		response.sendRedirect("SalidasForm.jsp");
   		session.setAttribute("loggedIn", true);
   		System.out.println("goodlogin");
   		session.setAttribute("priv", priv);
	}else if(priv==2){
		session.setAttribute( "state","none");
   		session.setAttribute( "FullName",fullName );
   		session.setAttribute("priv", priv);
   		response.sendRedirect("AdminCat.jsp");
   		session.setAttribute("loggedIn", true);
   		System.out.println("goodlogin");
	}
	
	MysqlLogin.disconnect();
	aLLogin.clear();
%>
